<?php
/**
 * Created by PhpStorm.
 * User: Zhoujinda
 * Date: 2016/3/24
 * Time: 15:55
 */

namespace Bbs\Api;

use Bbs\Model\ForumSilentModel;
// use Bbs\Model\BbsMemberViewModel;
// use Bbs\Model\ForumAdmingroupModel;
// use Bbs\Model\VUserInfoModel;
use Common\Api\Api;

class ForumSilentApi extends Api{

    /**
     * 添加
     */
    const ADD = "Bbs/ForumSilent/add";
    const COUNT = "Bbs/ForumSilent/count";
    /**
     * 保存
     */
    const SAVE = "Bbs/ForumSilent/save";
    /**
     * 保存根据ID主键
     */
    const SAVE_BY_ID = "Bbs/ForumSilent/saveByID";

    /**
     * 删除
     */
    const DELETE = "Bbs/ForumSilent/delete";

    /**
     * 查询
     */
    const QUERY = "Bbs/ForumSilent/query";
    /**
     * 禁言用户分页查询
     */
    const QUERY_SILENT = "Bbs/ForumSilent/querySilent";
    /**
     * 查询一条数据
     */
    const GET_INFO = "Bbs/ForumSilent/getInfo";

    /**
     * 插入多条数据
     */
    const ADD_ALL = "Bbs/ForumSilent/addAll";

    /**
     * 无分页查询
     */
    const QUERY_NO_PAGING = "Bbs/ForumSilent/queryNoPaging";


    protected function _init(){
        $this -> model = new ForumSilentModel();
    }

	public function querySilent($map = null, $page = array('curpage'=>0,'size'=>10), $order = false, $params = false, $fields = false) {
		$query = $this->model->alias('s')->group('s.uid')->distinct(ture)->join('LEFT JOIN common_member as m on m.uid=s.uid');
		if(!is_null($map))    $query = $query->where($map);
		if(false !== $order)  $query = $query->order($order);
		if(false !== $fields) $query = $query->field($fields);

		$list = $query -> page($page['curpage'] . ',' . $page['size']) -> select();//->buildSql();//
		// dump($list);exit;
		if (false === $list) {
			return $this -> apiReturnErr($this -> model -> getDbError());
		}

		$count = $this->model->alias('s')->group('s.uid')->distinct(true)->join('LEFT JOIN common_member as m on m.uid=s.uid')-> where($map) -> count();
		// 查询满足要求的总记录数
		$Page = new \Think\Page($count, $page['size']);
		//分页跳转的时候保证查询条件
		if (false !== $params) {
			foreach ($params as $key => $val) {
				$Page -> parameter[$key] = urlencode($val);
			}
		}
		// 实例化分页类 传入总记录数和每页显示的记录数
		$show = $Page -> show();

		return $this -> apiReturnSuc(array("show" => $show, "list" => $list));
	}

}